<template>
  <div id="home">
    <div class="home-loding">
      <van-loading size="60px" type="spinner"></van-loading>
      <p>加载中...</p>
    </div>
  </div>
</template>

<script>
import modelFunctions from "../../utils/modelFunction";
import * as types from "../../store/mutation-types";
import { storage } from "@/plugins/storage";
export default {
  data() {
    return {
      code: ""
    };
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      let param = modelFunctions.urlParam();
      let uri = "http://10.19.92.209:8990";
      console.log("param", param);
      if (param && param.access_token) {
        this.$store.commit(types.SET_ACCESS_TOKEN, param);
        this.getOnline(param);
      }
      // if (param && param.code) {
      //   this.code = param.code;
      //   this.api.oauthToken({ code: this.code, redirectUri: uri }).then(res => {
      //     this.$store.commit(types.SET_ACCESS_TOKEN, res);
      //     this.getOnline(res);
      //   });
      // }
    },
    getOnline(data) {
      this.api.onlinePay({ authToken: data.access_token }).then(res => {
        this.$store.commit(types.SET_PAY_INFO, res);
        this.$router.replace("/pay");
      });
    }
  }
};
</script>

<style lang="less">
#home {
  width: 100%;
  height: 100%;
  position: relative;

  .home-loding {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}
</style>
